package com.wyp168.leetcode;

/**
 * @ClassName HammingWeight
 * @Description TODO
 * @Author wyp168
 * @Date 2022/6/26 11:45
 */
public class HammingWeight {
    public static void main(String[] args) {
        System.out.println(hammingWeight(2));
    }
    public static int hammingWeight(int n) {
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if (((n >>> i) & 1) == 1) {
                count ++;
            }
        }
        return count;
    }
}
